package com.edu.exam.enums.grading;

import com.edu.exam.enums.core.BaseEnum;

/**
 * 权限级别枚举
 *
 * @author System
 * @version 1.0.0
 * @since 2025-11-13
 */
public enum PermissionLevel implements BaseEnum {

    /** 只读 */
    READ_ONLY("READ_ONLY", "只读"),

    /** 评论 */
    COMMENT("COMMENT", "评论"),

    /** 编辑 */
    EDIT("EDIT", "编辑"),

    /** 管理 */
    MODERATE("MODERATE", "管理"),

    /** 完全权限 */
    FULL("FULL", "完全权限"),

    /** 管理员 */
    ADMIN("ADMIN", "管理员");

    private final String code;
    private final String description;

    PermissionLevel(String code, String description) {
        this.code = code;
        this.description = description;
    }

    @Override
    public String getCode() {
        return code;
    }

    @Override
    public String getDescription() {
        return description;
    }

    /**
     * 从代码获取枚举值
     *
     * @param code 代码
     * @return 对应的枚举值
     * @throws IllegalArgumentException 如果代码无效
     */
    public static PermissionLevel fromCode(String code) {
        for (PermissionLevel permission : values()) {
            if (permission.getCode().equals(code)) {
                return permission;
            }
        }
        throw new IllegalArgumentException("Unknown PermissionLevel code: " + code);
    }

    @Override
    public String toString() {
        return this.code + "(" + this.description + ")";
    }
}